#ifndef PORTHANDLER_H
#define PORTHANDLER_H
#include <QObject>
#include <QTimer>
#include <QMutex>
#include "QSerialPort.hpp"

class Led;

class PortHandler : public QObject
{
	Q_OBJECT

	class MyThread : public QThread
	{
	public:
		using QThread::msleep;
	};

	QSerialPort* port;
	int portState;
	QByteArray colorBuffer;
    int startByte;

public:
	PortHandler();
	~PortHandler();

	enum PortState{
		Open,
		Close,
		OpenError
	};

	bool open(QString);
    void close();
	void setLeds(QList<Led*> &list);
	int getPortState(){ return portState; }
    void setStartByte(int byte) { startByte = byte; }
    void sendData();

private slots:
	void onPortOK();
	void onPortFail();
};

#endif // PORTHANDLER_H
